CheckSystem = {}


-- Woot Took system to testing stage!



-- Main Function CheckSystem -- No actual AnimatedActions or Scenes do get played from here. We will use ActionHandler.Lua for that. This script simply hands "values" to there.
function CheckSystem.ToggleSystem()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		CheckSystemActivator = true
		CheckSystemErrorHandler = true
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		CheckSystemActivator = false
		CheckSystemErrorHandler = false
	end
end

function CheckSystem.TurnOffAllChecks()
	IsAttachedToPedAndWaterCheckPed = false
	IsAttachedToPedAndWaterCheckObj = false
	IsAttachedToPedAndWaterCheckVeh = false
	IsAttachedToPedAndAirCheckPed = false
	IsAttachedToPedAndAirCheckObj = false
	IsAttachedToPedAndAirCheckVeh = false
	ScreenCheckPed = false
	ScreenCheckObj = false
	ScreenCheckVeh = false
	EntityTypePed = false
	EntityTypeObj = false
	EntityTypeVeh = false
	WaterCheckPed = false
	WaterCheckObj = false
	WaterCheckVeh = false
	AirCheckPed = false
	AirCheckObj = false
	AirCheckVeh = false
	MissionEntityCheckPed = false
	MissionEntityCheckObj = false
	MissionEntityCheckVeh = false
	DeadCheckPed = false
	DeadCheckObj = false
	DeadCheckVeh = false
	IsAttachedToObjCheckPed = false
	IsAttachedToObjCheckObj = false
	IsAttachedToObjCheckVeh = false
	IsAttachedToPedCheckPed = false
	IsAttachedToPedCheckObj = false
	IsAttachedToPedCheckVeh = false
	IsAttachedToVehicleCheckPed = false
	IsAttachedToVehicleCheckObj = false
	IsAttachedToVehicleCheckVeh = false
	IsAttachedToPlayerCheckPed = false
	IsAttachedToPlayerCheckObj = false
	IsAttachedToPlayerCheckVeh = false
	IsAttachedCheckPed = false
	IsAttachedCheckObj = false
	IsAttachedCheckVeh = false
	IsAttachedToPedAndDeadCheckPed = false	
	IsAttachedToPedAndDeadCheckObj = false
	IsAttachedToPedAndDeadCheckVeh = false
	IsAttachedToPedAndMissionEntityCheckPed = false
	IsAttachedToPedAndMissionEntityCheckObj = false
	IsAttachedToPedAndMissionEntityCheckVeh = false
end


function CheckSystem.ModelNameSet()
	natives.GAMEPLAY.DISPLAY_ONSCREEN_KEYBOARD(true, "", "", "", "", "", "", 50);
	NewEntityListUpdate = true	
end

function CheckSystem.NotFoundMessage()

end


-- CheckSystem tick
function CheckSystem.tick()


	------------------------------------------------------------------TO ADD NEW OBJECTS! This is used during the alpha state of this mod.
	if NewEntityListUpdate then
		natives.GAMEPLAY.UPDATE_ONSCREEN_KEYBOARD()
		local NameObjectUpdate = natives.GAMEPLAY.UPDATE_ONSCREEN_KEYBOARD()
		if (NameObjectUpdate == 1) then
			SaveToFileNewEntity = true
			NewEntityListUpdate = false
		end
	end
	
	if SaveToFileNewEntity then
		local result = natives.GAMEPLAY.GET_ONSCREEN_KEYBOARD_RESULT()
		local ModelToSave = ModelToPass
		print(ModelToSave)
		if TESTING.readFile("GTALua/addons/AnimatedActions/NewObjectList.txt") == nil then 
			print(" ")
			print("ERROR: NO FILE FOUND!")
			print("CREATING: NEW FILE IS BEING CREATED!")
			TESTING.writeFile("GTALua/addons/AnimatedActions/NewObjectList.txt", "")
			print(" ")
			print("CREATING: NEW FILE HAS BEEN CREATED!")
		end
		TESTING.writeFile("GTALua/addons/AnimatedActions/NewObjectList.txt",("\n"))
		TESTING.writeFile("GTALua/addons/AnimatedActions/NewObjectList.txt", "["..result.."] = ")
		TESTING.writeFile("GTALua/addons/AnimatedActions/NewObjectList.txt", ModelToSave..", ")
		print("SAVING: ENTITY AND HASH HAS BEEN ADDED TO THE LIST!")
		print("INFO: FILE CAN BE FOUND INSIDE THE ANIMATEDACTIONS FOLDER (NEWOBJECTLIST.TXT)")
		SaveToFileNewEntity = false
		DoneNamingEntity = true
	end
	------------------------------------------------------------------TO ADD NEW OBJECTS!




--[[
This is where the magic happens aka the detection stuff.
	Z = AnimResearchNumb-1
	AnimResearchNumb = Z
	if (Z < 1) then Z = 1 end
Use 
--========================================================================"Name"===
to add new main categories.

--]]	
--====================================================================================================	
	if ErrorCounter then
		SysTimerCounter = SysTimer+1
		SysTimer = SysTimerCounter
	end
	
	-- Error Handler -- Maybe one of the most important parts of this script as it has to stop bad things from happening.
	if CheckSystemErrorHandler then 
	
		if NoFoundPed and NoFoundVehicle and NoFoundObject and NoFoundWorldObject then
			CheckEntityModel = false
			CheckSystemActivator = false
			ErrorCounter = true
			if SysTimer == 50 then
				for PrintI = 1,100 do
					print(" ")
				end
				print("=========================================================== ")
				print("||===============S=Y=S=T=E=M==M=E=S=S=A=G=E===============||")
				print("||                                                        ||")
				print("|| THIS WORLDOBJECT/PED/OBJECT/VEHICLE IS UNLISTED.       ||")
				print("|| PRESS X TO NAME IT.                                    ||")
				print("|| OR PRESS Z TO CONTINUE.                                ||")
				print("|| PLEASE GIVE THEM NAMES ACCORDING TO HOW THEY LOOK.     ||")
				print("|| EXAMPLE : TRASH_CONTAINER_GREEN_01                     ||")
				print("|| EXAMPLE : PED_WHITESHIRT_BLUEPANTS_01                  ||")
				print("|| AFTER YOU GOT QUITE A FEW SEND IT TO SOD.              ||")
				print("|| IF YOU JUST RUN INTO A SINGLE ONE COMMENT IT =D.       ||")
				print("||                                                        ||")
				print("||========================================================||")
				print("=========================================================== ")
				SysTimer = 0
				ErrorCounter = false
			end
			if IsKeyDown(KEY_X) then
				CheckSystem.ModelNameSet()
			end
			if IsKeyDown(KEY_Z) then
				print(" ")
				print("INFO: SCRIPT CONTINUED")
				EntityToCheck = nil
				NoFoundPed = false
				NoFoundVehicle = false
				NoFoundObject = false
				NoFoundWorldObject = false
				CheckSystemErrorHandler = false
				CheckSystemActivator = true
			end
			if DoneNamingEntity == true then
				print(" ")
				print("INFO: SCRIPT CONTINUED")
				EntityToCheck = nil
				NoFoundPed = false
				NoFoundVehicle = false
				NoFoundObject = false
				NoFoundWorldObject = false	
				CheckSystemErrorHandler = false
				CheckSystemActivator = true
			end
		end
	end
	
	

	
	-- Model Check -- Name says what it does. -------------------------------------------------------
	if CheckEntityModel then
		local ModelCheck = natives.ENTITY.GET_ENTITY_MODEL(EntityToCheck)
		ModelToPass = ModelCheck ------------------------------------------------TO ADD NEW OBJECTS
		if PedFound == 1 or VehicleFound == 1 or ObjectFound == 1 or WorldObjectFound == 1 then
			PedFound = 0
			VehicleFound = 0
			ObjectFound = 0
			WorldObjectFound = 0
		end
	
		--Check for ped
		for k, PedModelName in pairs(PedNamesList) do
			local PedModelHash = natives.GAMEPLAY.GET_HASH_KEY(PedModelName)
			if PedModelHash == ModelCheck then
				NoFoundPed = false
				PedFound = 1
				CheckedEntityName = PedModelName
				natives.UI.SET_TEXT_FONT(7)
				natives.UI.SET_TEXT_PROPORTIONAL(0.5)
				natives.UI.SET_TEXT_SCALE(0.0, 0.35)
				natives.UI.SET_TEXT_COLOUR(255, 255, 255, 150)
				natives.UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
				natives.UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
				natives.UI.SET_TEXT_DROP_SHADOW()
				natives.UI.SET_TEXT_OUTLINE()
				natives.UI._SET_TEXT_ENTRY("STRING")
				natives.UI._ADD_TEXT_COMPONENT_STRING(PedModelName)
				natives.UI._DRAW_TEXT(0.02, 0.02)
				print(PedModelName)
				if EntityTypePed == true and ScreenCheckPed == true and DeadCheckPed == true then
					Medic_Inspect = true
				end
			end
			if k == #PedNamesList and PedFound ~= 1 then
				NoFoundPed = true
			end
		end
				
		--Check for vehicle
		for k, VehModelName in pairs(VehicleNamesList) do
			local VehModelHash = natives.GAMEPLAY.GET_HASH_KEY(VehModelName)
			
			if PedUsesThisVehicle ~= nil then
				local VehPedIsInHash = natives.ENTITY.GET_ENTITY_MODEL(PedUsesThisVehicle)
				if VehModelHash == VehPedIsInHash then
					NoFoundVehicle = false
					VehicleFound = 1
					CheckedEntityName = VehModelName
					natives.UI.SET_TEXT_FONT(7)
					natives.UI.SET_TEXT_PROPORTIONAL(0.5)
					natives.UI.SET_TEXT_SCALE(0.0, 0.35)
					natives.UI.SET_TEXT_COLOUR(255, 255, 255, 150)
					natives.UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
					natives.UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
					natives.UI.SET_TEXT_DROP_SHADOW()
					natives.UI.SET_TEXT_OUTLINE()
					natives.UI._SET_TEXT_ENTRY("STRING")
					natives.UI._ADD_TEXT_COMPONENT_STRING(VehModelName)
					natives.UI._DRAW_TEXT(0.02, 0.04)
					print(VehModelName)
				end
			end
			if VehModelHash == ModelCheck then
				VehicleFound = 1
				CheckedEntityName = VehModelName
				natives.UI.SET_TEXT_FONT(7)
				natives.UI.SET_TEXT_PROPORTIONAL(0.5)
				natives.UI.SET_TEXT_SCALE(0.0, 0.35)
				natives.UI.SET_TEXT_COLOUR(255, 255, 255, 150)
				natives.UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
				natives.UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
				natives.UI.SET_TEXT_DROP_SHADOW()
				natives.UI.SET_TEXT_OUTLINE()
				natives.UI._SET_TEXT_ENTRY("STRING")
				natives.UI._ADD_TEXT_COMPONENT_STRING(VehModelName)
				natives.UI._DRAW_TEXT(0.02, 0.04)
				print(VehModelName)
			end
			if k == #VehicleNamesList and VehicleFound ~= 1 then
				NoFoundVehicle = true
			end
		end
				
		--Check for object
		for k, ObjModelName in pairs(ObjectNamesList) do
			local ObjModelHash = natives.GAMEPLAY.GET_HASH_KEY(ObjModelName)
			if ObjModelHash == ModelCheck then
				NoFoundObject = false
				ObjectFound = 1
				CheckedEntityName = ObjModelName
				natives.UI.SET_TEXT_FONT(7)
				natives.UI.SET_TEXT_PROPORTIONAL(0.5)
				natives.UI.SET_TEXT_SCALE(0.0, 0.35)
				natives.UI.SET_TEXT_COLOUR(255, 255, 255, 150)
				natives.UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
				natives.UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
				natives.UI.SET_TEXT_DROP_SHADOW()
				natives.UI.SET_TEXT_OUTLINE()
				natives.UI._SET_TEXT_ENTRY("STRING")
				natives.UI._ADD_TEXT_COMPONENT_STRING(ObjModelName)
				natives.UI._DRAW_TEXT(0.02, 0.06)
				print(ObjModelName)
			end

			if k == #ObjectNamesList and ObjectFound ~= 1 then
				NoFoundObject = true
			end
			if ObjectFound == 1 then
				if EntityTypeObj == true and ScreenCheckObj == true then
				end
			end
		end	
		
		for WorldObjectName, WorldObjectHash in pairs(WorldObjectList) do  -- Requires manual input of the Last object on the list! So thats why we add new ones to the front =D
			if WorldObjectHash == ModelCheck then
				NoFoundWorldObject = false
				WorldObjectFound = 1
				CheckedEntityName = WorldObjectName
				natives.UI.SET_TEXT_FONT(7)
				natives.UI.SET_TEXT_PROPORTIONAL(0.5)
				natives.UI.SET_TEXT_SCALE(0.0, 0.35)
				natives.UI.SET_TEXT_COLOUR(255, 255, 255, 150)
				natives.UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
				natives.UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
				natives.UI.SET_TEXT_DROP_SHADOW()
				natives.UI.SET_TEXT_OUTLINE()
				natives.UI._SET_TEXT_ENTRY("STRING")
				natives.UI._ADD_TEXT_COMPONENT_STRING(WorldObjectName)
				natives.UI._DRAW_TEXT(0.02, 0.08)
				print(WorldObjectName)
			end
			if WorldObjectFound ~= 1 and WorldObjectName == "Wooden_Fence_02" then
				NoFoundWorldObject = true
			end
			if WorldObjectFound == 1 then
				if EntityTypeObj == true and ScreenCheckObj == true then
				end
			end
		end
		CheckEntityModel = false
	end
	
	
	-- Check System -- Preforms checks on the entity and will activate Systems functions accordingly.
	if CheckSystemActivator then
		EntityToCheck = nil
		local c_FirstCheck = CMemoryBlock(4)
		natives.PLAYER._0x2975C866E6713290(ply, c_FirstCheck)
		EntityToCheck = c_FirstCheck:ReadDWORD32(0)
		c_FirstCheck:Release()
		if EntityToCheck ~= nil then
			PedUsesThisVehicle = nil
			CheckSystem.TurnOffAllChecks()
		
		
			--========================================================================"Ped"===
			if natives.ENTITY.IS_ENTITY_A_PED(EntityToCheck) == true then
				EntityTypePed = true
				CheckEntityModel = true
				print("EntityTypePed")
				CheckSystemErrorHandler = true

				
				if natives.ENTITY.IS_ENTITY_ON_SCREEN(EntityToCheck) == true then
					ScreenCheckPed = true
					print("ScreenCheckPed")
					
					if natives.ENTITY.IS_ENTITY_ATTACHED(EntityToCheck) == true then	
						IsAttachedCheckPed = true
						print("IsAttachedCheckPed")
						
						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ENTITY(EntityToCheck, plyPed) == true then
							IsAttachedToPlayerCheckPed = true
							print("IsAttachedToPlayerCheckPed")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToPlayerAndDeadCheckPed = true
								print("IsAttachedToPlayerAndDeadCheckPed")
								
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToPlayerAndMissionEntityCheckPed = true
								print("IsAttachedToPlayerAndMissionEntityCheckPed")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToPlayerAndAirCheckPed = true
								print("IsAttachedToPlayerAndAirCheckPed")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToPlayerAndWaterCheckPed = true
								print("IsAttachedToPlayerAndWaterCheckPed")
							
							end	
							
						end
							
						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_VEHICLE(EntityToCheck) == true then
							IsAttachedToVehicleCheckPed = true
							print("IsAttachedToVehicleCheckPed")
							PedUsesThisVehicle = natives.PED.GET_VEHICLE_PED_IS_USING(EntityToCheck)

							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToVehicleAndDeadCheckPed = true
								print("IsAttachedToVehicleAndDeadCheckPed")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToVehicleAndMissionEntityCheckPed = true
								print("IsAttachedToVehicleAndMissionEntityCheckPed")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToVehicleAndAirCheckPed = true
								print("IsAttachedToVehicleAndAirCheckPed")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToVehicleAndWaterCheckPed = true
								print("IsAttachedToVehicleAndWaterCheckPed")
							
							end

						end

						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_PED(EntityToCheck) == true then
							IsAttachedToPedCheckPed = true
							print("IsAttachedToPedCheckPed")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToPedAndDeadCheckPed = true
								print("IsAttachedToPedAndDeadCheckPed")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToPedAndMissionEntityCheckPed = true
								print("IsAttachedToPedAndMissionEntityCheckPed")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToPedAndAirCheckPed = true
								print("IsAttachedToPedAndAirCheckPed")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToPedAndWaterCheckPed = true
								print("IsAttachedToPedAndWaterCheckPed")
							
							end	
							
						end

						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_OBJECT(EntityToCheck) == true then
							IsAttachedToObjCheckPed = true
							print("IsAttachedToObjCheckPed")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToObjAndDeadCheckPed = true
								print("IsAttachedToObjAndDeadCheckPed")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToObjAndMissionEntityCheckPed = true
								print("IsAttachedToObjAndMissionEntityCheckPed")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToObjAndAirCheckPed = true
								print("IsAttachedToObjAndAirCheckPed")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToObjAndWaterCheckPed = true
								print("IsAttachedToObjAndWaterCheckPed")
							
							end
							
						end		
					end
					
					if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
						DeadCheckPed= true
						print("DeadCheckPed")
					
					end
				
					
					if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
						MissionEntityCheckPed = true
						print("MissionEntityCheckPed")
					
					end				
					
					if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
						AirCheckPed = true
						print("AirCheckPed")
					
					end

					if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
						WaterCheckPed = true
						print("WaterCheckPed")
					end								
		
				end
			end




	--========================================================================"Vehicle"===
			if natives.ENTITY.IS_ENTITY_A_VEHICLE(EntityToCheck) == true then
				EntityTypeVeh = true
				CheckEntityModel = true
				print("EntityTypeVeh")
				CheckSystemErrorHandler = true

				if natives.ENTITY.IS_ENTITY_ON_SCREEN(EntityToCheck) == true then
					ScreenCheckVeh = true
					print("ScreenCheckVeh")
				
					if natives.ENTITY.IS_ENTITY_ATTACHED(EntityToCheck) == true then	
						IsAttachedCheckVeh = true
						print("IsAttachedCheckVeh")
						
						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ENTITY(EntityToCheck, plyPed) == true then
							IsAttachedToPlayerCheckVeh = true
							print("IsAttachedToPlayerCheckVeh")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToPlayerAndDeadCheckVeh = true
								print("IsAttachedToPlayerAndDeadCheckVeh")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToPlayerAndMissionEntityCheckVeh = true
								print("IsAttachedToPlayerAndMissionEntityCheckVeh")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToPlayerAndAirCheckVeh = true
								print("IsAttachedToPlayerAndAirCheckVeh")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToPlayerAndWaterCheckVeh = true
								print("IsAttachedToPlayerAndWaterCheckVeh")
							
							end	
							
						end
							
						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_VEHICLE(EntityToCheck) == true then
							IsAttachedToVehicleCheckVeh = true
							print("IsAttachedToVehicleCheckVeh")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToVehicleAndDeadCheckVeh = true
								print("IsAttachedToVehicleAndDeadCheckVeh")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToVehicleAndMissionEntityCheckVeh = true
								print("IsAttachedToVehicleAndMissionEntityCheckVeh")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToVehicleAndAirCheckVeh = true
								print("IsAttachedToVehicleAndAirCheckVeh")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToVehicleAndWaterCheckVeh = true
								print("IsAttachedToVehicleAndWaterCheckVeh")
							
							end	
							
						end

						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_PED(EntityToCheck) == true then
							IsAttachedToPedCheckVeh = true
							print("IsAttachedToPedCheckVeh")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToPedAndDeadCheckVeh = true
								print("IsAttachedToPedAndDeadCheckVeh")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToPedAndMissionEntityCheckVeh = true
								print("IsAttachedToPedAndMissionEntityCheckVeh")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToPedAndAirCheckVeh = true
								print("IsAttachedToPedAndAirCheckVeh")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToPedAndWaterCheckVeh = true
								print("IsAttachedToPedAndWaterCheckVeh")
							
							end	
							
						end

						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_OBJECT(EntityToCheck) == true then
							IsAttachedToObjCheckVeh = true
							print("IsAttachedToObjCheckVeh")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToObjAndDeadCheckVeh = true
								print("IsAttachedToObjAndDeadCheckVeh")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToObjAndMissionEntityCheckVeh = true
								print("IsAttachedToObjAndMissionEntityCheckVeh")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToObjAndAirCheckVeh = true
								print("IsAttachedToObjAndAirCheckVeh")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToObjAndWaterCheckVeh = true
								print("IsAttachedToObjAndWaterCheckVeh")
							
							end	
							
						end				
						
					end
					
					if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
						DeadCheckVeh = true
						print("DeadCheckVeh")
		
					end
					
					if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
						MissionEntityCheckVeh = true
						print("MissionEntityCheckVeh")
						
					end					
					
					
					if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
						AirCheckVeh = true
						print("AirCheckVeh")

					end

					if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
						WaterCheckVeh = true
						print("WaterCheckVeh")

					end								

				end
				
			end


	--========================================================================"Object"===
			
			if natives.ENTITY.IS_ENTITY_AN_OBJECT(EntityToCheck) == true then
				EntityTypeObj = true
				CheckEntityModel = true
				print("EntityTypeObj")
				CheckSystemErrorHandler = true
				
				if natives.ENTITY.IS_ENTITY_ON_SCREEN(EntityToCheck) == true then
					ScreenCheckObj = true
					print("ScreenCheckObj")
				
					if natives.ENTITY.IS_ENTITY_ATTACHED(EntityToCheck) == true then	
						IsAttachedCheckObj = true
						print("IsAttachedCheckObj")
					
						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ENTITY(EntityToCheck, plyPed) == true then
							IsAttachedToPlayerCheckObj = true
							print("IsAttachedToPlayerCheckObj")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToPlayerAndDeadCheckObj = true
								print("IsAttachedToPlayerAndDeadCheckObj")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToPlayerAndMissionEntityCheckObj = true
								print("IsAttachedToPlayerAndMissionEntityCheckObj")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToPlayerAndAirCheckObj = true
								print("IsAttachedToPlayerAndAirCheckObj")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToPlayerAndWaterCheckObj = true
								print("IsAttachedToPlayerAndWaterCheckObj")
							
							end	
							
						end
							
						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_VEHICLE(EntityToCheck) == true then
							IsAttachedToVehicleCheckObj = true
							print("IsAttachedToVehicleCheckObj")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToVehicleAndDeadCheckObj = true
								print("IsAttachedToVehicleAndDeadCheckObj")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToVehicleAndMissionEntityCheckObj = true
								print("IsAttachedToVehicleAndMissionEntityCheckObj")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToVehicleAndAirCheckObj = true
								print("IsAttachedToVehicleAndAirCheckObj")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToVehicleAndWaterCheckObj = true
								print("IsAttachedToVehicleAndWaterCheckObj")
							
							end	
							
						end


						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_PED(EntityToCheck) == true then
							IsAttachedToPedCheckObj = true
							print("IsAttachedToPedCheckObj")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToPedAndDeadCheckObj = true
								print("IsAttachedToPedAndDeadCheckObj")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToPedAndMissionEntityCheckObj = true
								print("IsAttachedToPedAndMissionEntityCheckObj")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToPedAndAirCheckObj = true
								print("IsAttachedToPedAndAirCheckObj")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToPedAndWaterCheckObj = true
								print("IsAttachedToPedAndWaterCheckObj")
							
							end	
							
						end

						if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_OBJECT(EntityToCheck) == true then
							IsAttachedToObjCheckObj = true
							print("IsAttachedToObjCheckObj")
							
							if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
								IsAttachedToObjAndDeadCheckObj = true
								print("IsAttachedToObjAndDeadCheckObj")
				
							end
							
							if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
								IsAttachedToObjAndMissionEntityCheckObj = true
								print("IsAttachedToObjAndMissionEntityCheckObj")

							end				
							
							if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
								IsAttachedToObjAndAirCheckObj = true
								print("IsAttachedToObjAndAirCheckObj")
				
							end

							if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
								IsAttachedToObjAndWaterCheckObj = true
								print("IsAttachedToObjAndWaterCheckObj")
							
							end	
							
						end
						
					end
					
					if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
						DeadCheckObj = true
						print("DeadCheckObj")
		
					end
					
					if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
						MissionEntityCheckObj = true
						print("MissionEntityCheckObj")

					end				
					
					if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
						AirCheckObj = true
						print("AirCheckObj")
		
					end

					if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
						WaterCheckObj = true
						print("WaterCheckObj")
					
					end				
				end
			end
		end
	end 
--====================================================================== End of System CheckHandler

	
	
	

--========================================================================Start Selecting "scenes"		
--========================================================================End Selecting "scenes"	









--[[========================================================================"Collection of Checks"===
		
		if natives.ENTITY.IS_ENTITY_A_PED(EntityToCheck) == true then
		end

		if natives.ENTITY.IS_ENTITY_A_MISSION_ENTITY(EntityToCheck) == true then
		end
		
		if natives.ENTITY.IS_ENTITY_A_VEHICLE(EntityToCheck) == true then
		end
		
		if natives.ENTITY.IS_ENTITY_AN_OBJECT(EntityToCheck) == true then
		end
		
		if natives.ENTITY.IS_ENTITY_DEAD(EntityToCheck) == true then
		end
		
		if natives.ENTITY.IS_ENTITY_IN_AIR(EntityToCheck) == true then
		end

		if natives.ENTITY.IS_ENTITY_IN_WATER(EntityToCheck) == true then
		end

		if natives.ENTITY.IS_ENTITY_ON_SCREEN(EntityToCheck) == true then
		end

		if natives.ENTITY.ENTITY.IS_ENTITY_ATTACHED_TO_ENTITY(EntityToCheck) == true then
		end
		
		if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_VEHICLE(EntityToCheck) == true then
		end

		if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_PED(EntityToCheck) == true then
		end

		if natives.ENTITY.IS_ENTITY_ATTACHED_TO_ANY_OBJECT(EntityToCheck) == true then
		end
		
		if natives.ENTITY.IS_ENTITY_ATTACHED(EntityToCheck) == true then
		end
		

--]]
end

-- CheckSystem init
function CheckSystem.init()


	-- Unlisted DO SORT THESE!
	TESTCheckSystemActivator = false
	SitBenchDetect = false
	
	

	
	-- Startup & Essential Check System Parts--
	CheckSystemActivator = false -- Activates the Detection System.
	CheckEntityModel = false -- What model is the entity aka if it is a ped what ped is it. Will set the name of it towards a global value.
	
	-- Error Handler -- Put everything related to error handling here.
	CheckSystemErrorHandler = false
	NoFoundObject = false
	NoFoundPed = false
	NoFoundVehicle = false
	NoFoundWorldObject = false
	SaveToFileNewEntity = false
	NewEntityListUpdate = false
	DoneNamingEntity = false
	SysTimer = 0
	ErrorCounter = false
	
	
	-- CheckHandler -- (enter empty line between categories and name them. Always put the name first then the type FE: EntityType = name Ped = type)
	-- ( This part will pass along what the entity is doing and what or who it is. This way it can decide from there what to do. And by checking what entity it is we can attach a scene to a separate entity.)
	----------------------ScreenCheck
	ScreenCheckPed = false
	ScreenCheckObj = false
	ScreenCheckVeh = false
	--------------------------------------

	----------------------EntityType	
	EntityTypePed = false
	EntityTypeObj = false
	EntityTypeVeh = false
	--------------------------------------

	----------------------WaterCheck
	WaterCheckPed = false
	WaterCheckObj = false
	WaterCheckVeh = false
	--------------------------------------
	
	----------------------AirCheck
	AirCheckPed = false
	AirCheckObj = false
	AirCheckVeh = false
	--------------------------------------

	----------------------MissionEntityCheck
	MissionEntityCheckPed = false
	MissionEntityCheckObj = false
	MissionEntityCheckVeh = false
	--------------------------------------
	
	----------------------DeadCheck
	DeadCheckPed = false
	DeadCheckObj = false
	DeadCheckVeh = false
	--------------------------------------

	----------------------IsAttachedToObjCheck
	IsAttachedToObjCheckPed = false
	IsAttachedToObjCheckObj = false
	IsAttachedToObjCheckVeh = false
	--------------------------------------
	
	----------------------IsAttachedToPedCheck
	IsAttachedToPedCheckPed = false
	IsAttachedToPedCheckObj = false
	IsAttachedToPedCheckVeh = false
	--------------------------------------
	
	----------------------IsAttachedToVehicleCheck
	IsAttachedToVehicleCheckPed = false
	IsAttachedToVehicleCheckObj = false
	IsAttachedToVehicleCheckVeh = false
	--------------------------------------

	----------------------IsAttachedToPlayerCheck
	IsAttachedToPlayerCheckPed = false
	IsAttachedToPlayerCheckObj = false
	IsAttachedToPlayerCheckVeh = false
	--------------------------------------

	----------------------IsAttachedCheck
	IsAttachedCheckPed = false
	IsAttachedCheckObj = false
	IsAttachedCheckVeh = false
	--------------------------------------
	
	----------------------IsAttachedCheckToPedandDeadCheck
	IsAttachedToPedAndDeadCheckPed = false	
	IsAttachedToPedAndDeadCheckObj = false
	IsAttachedToPedAndDeadCheckVeh = false
	--------------------------------------

	----------------------IsAttachedToPedAndMissionEntityCheck
	IsAttachedToPedAndMissionEntityCheckPed = false
	IsAttachedToPedAndMissionEntityCheckObj = false
	IsAttachedToPedAndMissionEntityCheckVeh = false
	--------------------------------------

	----------------------IsAttachedToPedAndAirCheck
	IsAttachedToPedAndAirCheckPed = false
	IsAttachedToPedAndAirCheckObj = false
	IsAttachedToPedAndAirCheckVeh = false
	--------------------------------------

	----------------------IsAttachedToPedAndWaterCheck
	IsAttachedToPedAndWaterCheckPed = false
	IsAttachedToPedAndWaterCheckObj = false
	IsAttachedToPedAndWaterCheckVeh = false
	--------------------------------------

	
	
	

	
	
	
	
	
	
	
	
	
	
end

-- AnimatedActions Onerror 
function CheckSystem:OnError()
	--self:Kill()
	--addon.Load("RENAMEME")
end